package controller;

import java.rmi.RemoteException;
import java.util.zip.DataFormatException;

import server.FirewallException;
import server.GlobalLog;
import server.Log;
import server.NotExpertException;
import server.Protocol;
import server.ReadWriteException;
import server.Rule;
import server.RulesTableType;



/**
 * <p>Title: FireWall Project. UI Module </p>
 * <p>Description: The UI module is a conector between the user level and application level (iptable & logger)
 * 					it provide to the user to transfer orders (stop, start, clean, load, save, help) ,
 * 					create or remove rules in the firewall, show all firewall rules, change log state,
 * 					clean & read log</p>
 * <p>Copyright: Copyright (c) 2006</p>
 * @author FW team
 * @version 1.0
 */
public class FirewallSession {

	
	public Rule[] rules;	
	
	
	public FirewallSession(){
		rules = new Rule[11];
		rules[0]  = new Rule(1, 80, "http", Rule.permissionOpt.DENY );
		rules[1]  = new Rule(2, "123.123.123.123",60, Rule.permissionOpt.DENY );
		rules[2]  = new Rule(2, "123.123.123.123",60, Rule.permissionOpt.DENY );
		rules[3]  = new Rule(3, "234.234.234.234", 70, Rule.permissionOpt.DENY );
		rules[4]  = new Rule(4, "555.666.777.888",90, Rule.permissionOpt.DENY );
		rules[5]  = new Rule(5, "555.666.777.888",660, Rule.permissionOpt.DENY );
		rules[6]  = new Rule(6, null, 70, Rule.permissionOpt.DENY );
		rules[7]  = new Rule(7, "555.666.777.888",60, Rule.permissionOpt.ALLOW );
		rules[8]  = new Rule(8, null,40, Rule.permissionOpt.DENY );
		rules[9]  = new Rule(9, 60, "hahaha", Rule.permissionOpt.DENY );
		rules[10] = new Rule(10, "555.666.777.888",60, Rule.permissionOpt.DENY );
	}

	
	


//	public GlobalLog[] getGlobalLogs(int days) throws RemoteException, FirewallException
//	{
//		return new GlobalLog;
//	}


// CHECKED
	public  void turnOff()throws RemoteException, FirewallException, ReadWriteException {
		System.out.println("turn ON! ");
	}

	public  void turnOn()throws RemoteException, FirewallException, ReadWriteException {
		System.out.println("turn OFF! ");
		
	}
	
	public boolean isReadWrite()throws RemoteException {
		return true;
	}
	public boolean isExpert()  throws RemoteException {
		return true;
	}
	
	
	public  void addProtocol(Protocol protocol) throws RemoteException, FirewallException, ReadWriteException, NotExpertException{
		System.out.println("add protocol : " + protocol.protocol);
	}

// NAME - ok	
	
	
	public Log[]  getLogs(int days)throws RemoteException, FirewallException
	{
		System.out.println("getLoggerSessionsReports " + days);
		Log[] log = new Log[8];
		log[0] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		log[1] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		log[2] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		log[3] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		log[4] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2055, 80, "http", Log.actionOpt.ACCEPT) ;
		log[5] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80,null, Log.actionOpt.ACCEPT) ;
		log[6] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		log[7] = new Log( 4444,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2", 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		return log;
	}

	
	public Log[] getLogs(int days, String address, Integer port, Log.directOpt dir) throws RemoteException, FirewallException
	{
		System.out.println("getLoggerSessionsReports  ip: "+days  +  address + port +dir);
		Log[] log = new Log[1];
		log[0] = new Log( 1234,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2",
				 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		return log;
	}
	
	public Log[]  getLogs(int historyDepth, String protocol)throws RemoteException, FirewallException
	{
		System.out.println("getLoggerSessionsReports proto: " + protocol);
		Log[] log = new Log[1];
		log[0] = new Log( 4321,  Log.directOpt.IN, "10:10:20:1", "10:10:20:2",
				 80, 2078, 80, "http", Log.actionOpt.ACCEPT) ;
		return log;
	}



	public  Rule[] getRules(RulesTableType type, String ruleset)throws RemoteException, FirewallException
	{
		System.out.println("getRules! for " + ruleset);
		return  rules;
	}
	
	
	public  void addRule(RulesTableType type, String ruleset, Rule rule) throws RemoteException, FirewallException, ReadWriteException, NotExpertException
	{
		System.out.println("addRule to " +ruleset + " rule " + rule);
		rules[0] = rule;
	}

	public  void deleteRule(RulesTableType type, String ruleset, int id)throws RemoteException, FirewallException, ReadWriteException, NotExpertException
{
		System.out.println("deleteRule  " + id);
		
	}
	
	public  void setRuleSet(String ruleset)throws RemoteException, FirewallException, ReadWriteException
	{
		System.out.println("setRuleSet!"+ ruleset);
		
	}
	
	public void createRuleSet(String ruleset) throws RemoteException, FirewallException, ReadWriteException, NotExpertException
	{
		System.out.println("createRuleSet!"+ ruleset);
		
	}
	
	public void loadRuleSet(String name) throws RemoteException, FirewallException, ReadWriteException, NotExpertException
	{
		System.out.println("loadRuleSet!");
		
	}
	
	
	public String getCurrentRuleSet() throws RemoteException {
		
		System.out.println("getCurrentRuleSet!");
		return "ruleset1111";
	}
	
	public void enableLog() throws RemoteException, FirewallException, ReadWriteException{
		
	}
	
	public void disableLog() throws RemoteException, FirewallException, ReadWriteException{
		
	}



}
